package com.iqiju.guagua.redtone.video.controller;

import com.iqiju.guagua.redtone.video.common.Results;
import com.iqiju.guagua.redtone.video.service.WxMiniUserService;
import com.iqiju.guagua.redtone.video.vo.LoginVO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags = "权限接口")
public class LoginController {

    @Autowired
    private WxMiniUserService wxMiniUserService;



    @ApiImplicitParams({
            @ApiImplicitParam(name = "wxMiniAppId",value = "小程序自定义ID",required = true,dataType = "String",paramType = "path",example = "1201756694072651777"),
            @ApiImplicitParam(name = "code",value = "用户登录凭证",required = true,dataType = "String",paramType = "path",example = "a1s2d3"),
            @ApiImplicitParam(name = "channel",value = "分享渠道id（没有默认0）",required = true,dataType = "String",paramType = "path",example = "0"),
            @ApiImplicitParam(name = "shareUserId",value = "分享用户id（没有默认0）",required = true,dataType = "String",paramType = "path",example = "0")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 0, message = "接口返回成功"),
            @ApiResponse(code = 100, message = "参数传递错误，检查参数是否合法"),
            @ApiResponse(code = 200, message = "接口返回未知错误，请联系开发人员调试"),
            @ApiResponse(code = 500, message = "接口返回未知错误，请联系开发人员调试")
    })
    @ApiOperation(value = "登录接口", notes = "访问此接口，进行微信小程序简单登录")
    @PostMapping("/wx/mini/login/{wxMiniAppId}/{code}/{channel}/{shareUserId}")
    public Results<LoginVO> codeLogin(@PathVariable String wxMiniAppId, @PathVariable String code, @PathVariable String channel, @PathVariable String shareUserId){
        log.info("访问登录接口--------------------------------------------------");
        return wxMiniUserService.login(wxMiniAppId, code, channel, shareUserId);
    }
}
